# Maintainer: Andreas 'Segaja' Schleifer <archlinux at segaja dot de>

_gemname='simplecov-html'
pkgname="ruby-${_gemname}"
pkgver=0.12.3
pkgrel=2
pkgdesc='Default HTML formatter for SimpleCov code coverage tool for ruby 2.4+'
arch=('any')
url="https://github.com/simplecov-ruby/${_gemname}"
license=('MIT')
depends=('ruby')
checkdepends=('ruby-rake' 'ruby-simplecov')
options=(!emptydirs)
source=("${url}/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz")
sha512sums=('2b4499bafda739763f52cd05be37a8db4aea4780f0ec59f077cdac36cd00396def7b61b3c567b758d78de69dc2c921a2e454d2955d6f31932883b32b77b4d98b')

prepare() {
  cd "${_gemname}-${pkgver}"

  sed --in-place --regexp-extended 's|~>|>=|g' "${_gemname}.gemspec"
  sed --in-place --regexp-extended 's|git ls-files|find . -type f -not -path "*/\.git/*"|' "${_gemname}.gemspec"

  rm --verbose Gemfile*
}

build() {
  cd "${_gemname}-${pkgver}"

  gem build "${_gemname}.gemspec"
}

check() {
  cd "${_gemname}-${pkgver}"

  rake test
}

package() {
  cd "${_gemname}-${pkgver}"

  local _gemdir="$(gem env gemdir)"

  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "${pkgdir}/${_gemdir}" \
    --bindir "${pkgdir}/usr/bin" \
    "${_gemname}-${pkgver}.gem"

  # remove unrepreducible files
  rm --force --recursive --verbose \
    "${pkgdir}/${_gemdir}/cache/" \
    "${pkgdir}/${_gemdir}/gems/${_gemname}-${pkgver}/vendor/" \
    "${pkgdir}/${_gemdir}/doc/${_gemname}-${pkgver}/ri/ext/"

  find "${pkgdir}/${_gemdir}/gems/" \
    -type f \
    \( \
      -iname "*.o" -o \
      -iname "*.c" -o \
      -iname "*.so" -o \
      -iname "*.time" -o \
      -iname "gem.build_complete" -o \
      -iname "Makefile" \
    \) \
    -delete

  find "${pkgdir}/${_gemdir}/extensions/" \
    -type f \
    \( \
      -iname "mkmf.log" -o \
      -iname "gem_make.out" \
    \) \
    -delete

  install --verbose -D --mode=644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
  install --verbose -D --mode=644 *.md --target-directory "${pkgdir}/usr/share/doc/${pkgname}"
}
